package cn.stylefeng.guns.modular.basic.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;

import cn.stylefeng.guns.modular.basic.entity.StoreAccountRecord;
import cn.stylefeng.guns.modular.basic.mapper.StoreAccountRecordMapper;
import cn.stylefeng.guns.modular.basic.model.params.StoreAccountRecordParam;
import cn.stylefeng.guns.modular.basic.model.result.StoreAccountRecordResult;
import cn.stylefeng.guns.modular.basic.service.StoreAccountRecordService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 * 门店账户 服务实现类
 * </p>
 *
 * @author wp
 * @since 2025-09-01
 */
@Service
public class StoreAccountRecordServiceImpl extends ServiceImpl<StoreAccountRecordMapper, StoreAccountRecord> implements StoreAccountRecordService {

    @Override
    public void add(StoreAccountRecordParam param){
        StoreAccountRecord entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(StoreAccountRecordParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(StoreAccountRecordParam param){
        StoreAccountRecord oldEntity = getOldEntity(param);
        StoreAccountRecord newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public StoreAccountRecordResult findBySpec(StoreAccountRecordParam param){
        return null;
    }

    @Override
    public List<StoreAccountRecordResult> findListBySpec(StoreAccountRecordParam param){
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(StoreAccountRecordParam param,String condition){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param,condition);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(StoreAccountRecordParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private StoreAccountRecord getOldEntity(StoreAccountRecordParam param) {
        return this.getById(getKey(param));
    }

    private StoreAccountRecord getEntity(StoreAccountRecordParam param) {
        StoreAccountRecord entity = new StoreAccountRecord();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

}
